package com.edu.dk.security.impl;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import com.edu.dk.security.WebContext;

/**
 * 被<code>WebContext</code>支持的<code>HttpServletRequestWrapper</code>。
 *
 */
public abstract class AbstractRequestWrapper extends HttpServletRequestWrapper {
	private WebContext context;

	/**
	 * 创建一个request wrapper。
	 *
	 * @param context
	 *            request context
	 * @param request
	 *            request
	 */
	public AbstractRequestWrapper(WebContext context, HttpServletRequest request) {
		super(request);
		if (context == null) {
			throw new IllegalArgumentException("requestContext is NULL");
		}
		this.context = context;
	}

	/**
	 * 取得当前request所处的servlet context环境。
	 *
	 * @return <code>ServletContext</code>对象
	 */
	public ServletContext getServletContext() {
		return getWebContext().getServletContext();
	}

	/**
	 * 取得支持它们的<code>WebContext</code>。
	 *
	 * @return <code>WebContext</code>实例
	 */
	protected WebContext getWebContext() {
		return context;
	}
}
